Brilliant talk by John Cleese on creativity.
Finding solutions to problems in the middle of the night while sleeping has happened to me.  Usually that's how I fall sleep at night, thinking hard about a problem, or trying to build up an idea.  Having things on ones mind before sleeping probably does influence what we dream and think about while sleeping.