I know this question is definitely solved somewhere many times already, please enlighten me if you know of their existence, thanks.
Quick rundown: I want to compute
As I understand your question, you know the pitch and yaw of your device (from the magnetometer) and want to use this information to calculate the component of gravity along each of your (device) coordinate axes?
As a physicist I'm brought up with Euler angles instead of pitch-yaw-roll, but looking at http://en.wikipedia.org/wiki/Yaw,_pitch,_and_roll I would calculate this as follows:
Assume that your device is initially oriented along the global coordinate frame, so that gravity is gvec:={0,0,-g} (in the local frame). Now we have to calculate the local coordinates of gvec as we go through the yaw-pitch-roll (yaw doesn't do anything as you mention).
To me this is easiest with rotation matrices: we have to change the sign of the angles since gvec stays put. I'll do this with Mathematica because that's my hammer and this is a nail
yaw = RotationMatrix[-yawangle,{0,0,1}];
pitch = RotationMatrix[-pitchangle, {0,1,0}];
roll = RotationMatrix[-rollangle,{1,0,0}];
gvec={0,0,-g}
yaw.gvec
pitch.yaw.gvec
roll.pitch.yaw.gvec
The output is the local coordinates for gvec before yaw, and after yaw, pitch, and roll (so last line below should be your answer):
{0,0,-g}
{0,0,-g}
{g Sin[pitchangle],0,-g Cos[pitchangle]}
{g Sin[pitchangle],-g Cos[pitchangle] Sin[rollangle],-g Cos[pitchangle] Cos[rollangle]}