I always hit it about ten minutes before closing. The line is usually manageable and by the time you get off, you'll be walking through a deserted Disneyland and be able to take a picture of Sleeping Beauty Castle without people in front of it.
I once waited about 2 min to ride FNSV thanks to a cast member I made friends with the night before. She walked me and my wife up through the exit and talked to the loader who put us on the next sub. So I'd recommend that tactic if you cant make the opening or closing times work.