The details will vary according to what you mean exactly by yaw, pitch, roll. But here is a general way of transforming the axes. It may not be the best theoretical way to do it, but it works fine computationally.
Let rotations about the $X$-axis by an angle $\theta$ be denoted by $R_{X,\theta}$, and similarly for the other axes. A frame is then obtained by $$T_{\theta,\phi,\psi}:=R_{X,\phi}R_{Y,\theta}R_{Z,\psi}$$
If I understand your question correctly, you want the three angles that would give $T_1T_2^{-1}$ given two frames $T_1$, $T_2$.
- Calculate the matrix $S:=T_1T_2^{-1}$
- Calculate $\phi=\arctan_2(S_{3,3},-S_{2,3})$, $\theta=\arctan_2(\sqrt{S_{1,1}^2+S_{1,2}^2},S_{1,3})$, $\psi=\arctan_2(S_{1,1},-S_{1,2})$.
Then $\theta$, $\phi$, and $\psi$ are the required angles. Here $\arctan_2(x,y)$ is the modified arctan function that gives the angle in the correct quadrant.
Note that there may be different values of $\phi$, $\theta$, $\psi$ that give the same transformation $S$.