So using the image above I have two vectors, u and v. Vector u is formed using P1 and P2 which are two coordinates in 3D space. Vector v is formed using P1 and P3.
I wish to first rotate vector v around the Z axis until it lines up under vector u which is shown by w in the image. After that then rotate around the x axis, so it is in line with vector u. I wish to be able to calculate those two angles. Hopefully this makes sense.
The goal is to find angle a and b
The other trick is I wish to keep track of direction as well, meaning that the given two angles can be positive or negative.
I do know how to find the angle between two vectors but am unsure how to do so like above.

A counterclockwise (wrt order $(x, y)$) rotation of angle $\theta$ about the $z$-axis is given by the matrix $$M_{\theta,z}=\left(\matrix{\cos \theta& -\sin \theta&0\\\sin \theta& \cos \theta&0\\0&0&1\\}\right)$$
A counterclockwise (wrt order $(y, z)$) rotation of angle $\varphi$ about the $x$-axis is given by the matrix $$M_{\varphi,x}=\left(\matrix{1&0&0\\0&\cos \varphi& -\sin \varphi\\0&\sin \varphi& \cos \varphi\\}\right)$$
You have to find $\theta$ and $\varphi$ such that $M_{\varphi,x}\cdot M_{\theta,z}\cdot v=u$. If you know the coordinates of $u$ and $v$ this will give you a system of equations to solve.