As the title says, I am trying to find, for any rotation R, a unit vector $u = [u_x, u_y, 0]$, and two angles $\alpha$ and $\beta$, such that R is equal to a rotation of angle $\alpha$ around $u$ and a rotation of angle $\beta$ around $[0, 0, 1]$. I have trouble finding out if this is always possible, and if such a factorization is unique.
I am not particularly interested in $u$, $\alpha$ and $\beta$ directly, but more in the factorisation of $R$ as a product of rotation matrices or quaternions.
Going through Euler angles does not give me what I want because the composition of the pitch and roll rotations will give some amount of rotation around the Z axis. I have tried to express the problem through matrices and quaternions, and while some terms can be easily expressed (at least up to a sign), the computation gets too unwieldy for me.

Here is a computation using quaternions, which avoids any trigonometric computation.
For any quaternion $q = a i + b j + c k + d$, we say that it represents a vertical rotation if $a = b = 0$, and a horizontal rotation if $c = 0$. We want to factor any quaternion $q$ as $q^Hq^Z$, where $q^Z$ and $q^H$ respectively represent a verical and a horizontal rotation.
Let $q'= c k + d$. Then a direct computation shows that $q * \bar q'$ represents a horizontal rotation (where $\bar q' = -ck + d$ is the conjugate of $q'$). We therefore get the required factorization by setting $q^Z = q' / ||q'||$ and $q^H = q \bar q^Z$. ( ||q'|| = 0 implies that c = 0 and $q$ is already a horizontal rotation, in which case we can set $q^Z = 1$).
As a bonus, the same computation shows that $\bar q' * q$ also represents a horizontal rotation. So we get that the vertical rotation of the factorisation is independent of the order of the factorisation, i.e. for any unit $q$, $q = q^Z q^H_1 = q^H_2 q^Z$.