I'm sorry. I had missed what your goal was, and was distracted by the fact that the known variables are not independent. If you add these,

\(\displaystyle x^2+y^2 = a_{2}^2 cos^2\theta_2\)

\(\displaystyle (z-d)^2 = a_{2}^2 sin^2\theta_2\)

you find that

\(\displaystyle x^2+y^2+(z-d)^2 = a_2^2\)

So if you know any four of x, y, z, a, d, you can find the other. (What is \(\displaystyle d_1\)?) This may be important as a check; or it may be useful to simplify something.

Anyway, your work is all valid, but doesn't fully determine either angle, depending on their domains, because squaring lost information about the signs of the trig functions, and asin doesn't distinguish between acute and obtuse. If you know the angles are positive and acute, there is no issue.

To find \theta_2, I would just solve E3.

To find \theta_1, you can divide E2 by E1 and use the atan.

I haven't given enough thought to how to determine what quadrant each is in, or if they are ambiguous.