I’ll get you started, and see if you can calculate all three joint angles given values for $X$, $Y$, and $Z$.   If you cannot, we can continue peeling the onion until you are able to do that.  

You will have to manipulate the expressions for $X$, $Y$, and $Z$, and use trigonometric identities to solve for the individual joint values.  

Start with the easiest:  using the $X$ and $Y$ terms only, you should be able to write an expression that only involves th1.  It will be a tangent function that can be inverted to find th1.

Next, square the $X$ and $Y$ terms, and add them together.  This will eliminate th1 from the expression.   Subtract $Z$ squared from the remaining terms.  You should be left with expressions of a constant times [cos(th2 + th3) cos(th2) + sin(th2 + th3) sin(h2)].   Using a trigonometric identity, this can be solved for th3 using the inverse cos function. 

See if you can get to this point, then try other manipulations to solve for (th2 + th3), which will get you the last value.