Let $\hat{z}_0$ be the $z$-axis unit vector in the original coordinate system, and $\hat{z}_1$ in the new coordinate system. (Note that I do assume both have length $1$.)
To rotate $\hat{z}_0$ to $\hat{z}_1$, you need a rotation of $\theta$ around axis $\hat{a}$:
$$\left\lbrace\begin{array}{rcl}
\vec{a} &=& \hat{z}_0 \times \hat{z}_1 \\
\sin\theta &=& \lVert\vec{a}\rVert \\
\hat{a} &=& \frac{\vec{a}}{\lVert\vec{a}\rVert} \\
\cos\theta &=& \hat{z}_0 \cdot \hat{z}_1
\end{array}\right.$$
The reason we can use the cross product of the two (unit) vectors like this as the rotation axis may be unintuitive. The key is to remember that the cross product of $\vec{a}$ and $\vec{b}$ is perpendicular to both $\vec{a}$ and $\vec{b}$. If we rotate the coordinate system of $\vec{a}$ around this axis, by the angle between $\vec{a}$ and $\vec{b}$, the rotated $\vec{a}$ will be parallel to $\vec{b}$.
If we use $(x, y, z) = \hat{a}$, $s = \sin\theta$, $c = \cos\theta$, and $d = 1 - c = 1 - \cos\theta$, then the rotation matrix $\mathbf{R}$ needed (for $\mathbf{R} \hat{z}_0 = \hat{z}_1$; see Rotation matrix Wikipedia article for details) is
$$\mathbf{R} = \left [ \begin{matrix}
x^2 d + c & x y d - z s & x z d + y s \\
x y d + z s & y^2 d + c & y z d - x s \\
x z d - y s & y z d + x s & z^2 d + c
\end{matrix} \right ] $$
Do note that you do not need to use $\sin$, $\cos$, $\arcsin$, or $\arccos$ at all to construct the rotation matrix. I used them to remind readers of the definition of cross product and dot product for three-dimensional vectors.
Caveat: The method shown here is quite sound, but I was too lazy to verify the above math with respect to typos (and the order of the vectors in the cross product, and the direction of the rotation), so if you notice a problem or a typo or any other error, do let me know in a comment, so I can fix it.