Note: It is advisable to make drawings while following this solution.
Suppose the line has finite length and the line joins $(0,0,0)$ to point $(0,r,h)$. Immediately, we have
$$\tan\alpha = r/h$$
We rotate the coordinate system by $\beta$ around $z$ axis. Now we have two lines: one which stays at the same location relative to the old coordinate system, another rotates together with the coordinate system.
Project now the old line onto plane $X'Y'$. Call this line $\operatorname{OPLine}[X'Y']$. Notice that $\beta$ is now the angle between this projected line and $y'$ axis. And notice also, that this project line has length $r$.
Project $\operatorname{OPLine}[X'Y']$ onto plane $X'Z'$. If we denote $a$ the length of this projected line, we write
$$a = r \sin\beta$$
Project the new line onto plane $X'Z'$. Call this line $\operatorname{NPLine}[X'Z']$. Denote $\phi_{X'Z'}$ the angle between $\operatorname{OPLine}[X'Z']$ and $\operatorname{NPLine}[X'Z']$, which is one of the things you wanted in your question. We write
$$\tan\phi_{X'Z'} = a/h$$
Eliminating $a$, $h$ and $r$, we obtain
$$\tan\phi_{X'Z'} = \sin\beta \tan\alpha$$
The steps to obtain $\phi_{Y'Z'}$ are similar. The rest are left as exercises to the reader (as they often said).
We have two rotations, $\mathbf p$ and $\mathbf q$, and we want to find the rotation $\mathbf r$ such that applying $\mathbf p$ and then $\mathbf r$ is equivalent to applying $\mathbf q$.
In quaternions or full-strength rotation matrices, this is easy: $\mathbf q = \mathbf {rp}$, so $\mathbf r = \mathbf q\mathbf p^{-1}$.
Converting between quaternions and Euler angles is another problem, and of course depends on what form of Euler angles you're using. Wikipedia's got a page literally named Conversion between quaternions and Euler angles that looks pretty promising.
Best Answer
So given vector A = (2i,4j,5k) and vector B = (1i,3j,8k)
my theida (as shown in image above) would be:
Therefore,
cos(theida) = (2*1) + (5*8) / (sqrt(2^2 + 5^2) * sqrt(1^2+8^2))
theida = acos(42/(sqrt(29)*sqrt(65)))
theida = 14.68 deg
and similarly:
Therefore,
cos(phi) = (2*1) + (4*3) / (sqrt(2^2 + 4^2) * sqrt(1^2+3^2))
phi= acos(14/(sqrt(20)*sqrt(10)))
phi= 8.13 deg