I assume you're after projected shadows and not shadow volumes?
something like
http://www.opengl.org/archives/resource ... sld021.htm ? you'll still need to combine that with a model and projection matrix, probably by multiplying that matrix into the (model)view matrix at some point.
z-pass shadow volumes need just the sides, which requires that only some verts are extruded based upon the light position. z-fail needs front+back as well, but if you're already generating sides then its simpler to keep the front+back caps as part of the same mesh/batch. aside from you calling it 'stencil shadows', your matrix stuff seems unrelated...
.