Render ONLY the Alpha Channel
There is a feature for this

The Combined Pass includes an alpha channel:



The Render Layers Node has an Alpha output for it:



If using Cycles make sure to enable Film > Transparent in the Render Context.



If using Blender Render make sure to enable Transparency in the Materials Context.



There is no need to change the material for all the objects in your scene!

There is no need to use ID Masks for this either.

There are cases where using an ID Mask will cause you problems, for example if your materials have transparency. Observe this tree. Its leaves are texture planes, so if you use an ID mask you will only see the outline of the planes.



If rendering glass with a transparent background in Cycles, see this.