do an ID pass, its when you assign a surface shader of a different color to each mask you want in your scene. Then in your compositing package you can select that color and use it as a mask as you wish.