This article explains the math, benefits and issues of multi-pass compositing using V-Ray render elements as the basis.
All the techniques are applicable to render passes, generated by other rendering engines.
Introduction to Multi-Pass Compositing