Matt Ridley discusses some of the latest research into what dreams are for:
In another experiment, people were asked to remember a series of words, such as nurse, ill, patient, etc. Some hours later, they were asked to recall if certain words were in the list. They correctly rejected most of the wrong words—except the word "doctor," which was not in the list but sounds as if it should have been. Here's the surprise: The people who made this mistake most were the ones who had been to sleep in the meantime. Dreaming sleep had extracted the "gist" of the list.
According to this theory, dreaming is a symptom of such memory processing. Contrary to popular belief, dreaming occurs throughout sleep, not just in rapid-eye-movement sleep. But the dreams reported by people woken from non-REM sleep tend to be literal and straightforward recitations of recent experiences stored in the hippocampus. The later dreams of REM sleep incorporate more distant memories, becoming more fantastic and more emotional as the new memories get mixed with old ones in the cortex.