This script will create all your necessary mattes at once, based on your selection.

There are many ways to create mattes for compositing. One possibilty would be to create several passes for each matte. Another one is to use shaders like this or mental rays object label channel, which randomly assign colors to each object. MM_Matte_Pass has several advantages over those methods:

Unlike passes: Easy to set up. You just have to select all your objects in a specific way to create all the mattes you need with one click.
Unlike passes: Renders fast. The script stores all the masks in channels and names them correctly. So you only have to render one pass to spit out up to 64 mattes.
Unlike object labels: Full control. You can combine objects into mattes and decide for yourself which mattes you want to create.
Unlike object labels: Since all the mattes are white and fully anti aliased, no problems can occur with overlapping objects.