Calculate tilt using 3 axis accelerometer?

  accelerometer, angle, c++, tilt

I have device and want to calculate its tilt (theta) angle using 3 axis accelerometer?
For the reference, I attached an image which showing how the device position in hand and need to calculate theta showing in the image. enter image description here
SO, anyone can give me the formula to calculate the theta angle with respect to the image?

Source: Windows Questions C++