There's a great Radiolab on sleep from years and years ago where they put forth all the scientific evidence that, evolutionarily, dreams are our brain's "fire drills" wherein it runs all our synaptic paths through the patterns that release the most hormones. In other words, things that freak us out are the things that it's going to hammer on during sleep. They further made the observation that the function of sleep, neurochemically, is to wash away the less successful decision trees so that the more prominent ones function more efficiently. In other words, yes - when you're tired and can no longer learn something, sleeping on it will allow your brain to accomplish the task with better utility. It's kind of like brushing away the chips before you continue engraving.
It's effective, too. That dream where your teeth fall out before a job interview? Actually lost a tooth before a job interview and wasn't even stressed. That one where you wake up late and only have 10 minutes left to do the final? Fuckin' 88% bitchez.
To be fair, however, both events happened in pants.