A layer mixer node allows you combine nodes with priority. The input at the bottom is prioritized over those at the top. So you feed your background window into the top input on the node, then the foreground into the next one down, and so on.
I think this can be applied to both your questions.
online editor | colorist | VFX | BD author
http://JuanSalvo.com