Wow, this question brings back memories. I'm pretty sure recording demos was the second code the community ever learned (the first being "$testcheats=1;"). In any case, type "$dorecorddemo=1;" into the console, and the next level you play will record a demo. Please note that they aren't cross-platform, so Mac demos won't work properly on Windows, and vice versa.
For your other question: clarification. Do you want the demo to keep playing in the background while the menus are open?