A few days ago I posted about hooking up a 27 inch Dell monitor in my office at work. Marcin posted a comment asking how I was able to use my MacBook Pro while the lid was closed. I responded that it just worked. Since then, I have hooked and unhooked my MacBook Pro a dozen times or so with the lid closed and have had mixed results. I did some searching today to see if there is a set of steps you can follow to keep from having issues - the issues being the laptop doesn't wake up after plugging in the external display and/or unplugging it.
Sure enough, there is a set of specific steps which you can read about on Apple's site.