To get the yaw and pitch you use trigonometry - I assume you have some working knowledge. Check out this wiki page for some useful diagrams to visualize the angles.
Letting Y = yaw, P = pitch.
First to get yaw you want:
tan(Y) = x/(-y)
Now to get pitch:
tan(P) = sqrt(x^2 + y^2)/z
To get the actual values for Y and P you'll need to use inverse tan, I've written it above using tan to make the derivation clearer.
Note that the minus signs depend on how you define you angles and axes, but you should get the idea.