Sensing tilt using accelerometer alone

The accelerometer is sensing the pull of gravity. If the accelerometer is flat the X and Y accelerations are 0 and the Z acceleration is -1g. As the accelerometer tilts the Z acceleration gets closer to 0 and the X and/or Y accelerations go up or down. Using some trig you can determine the pitch and roll angles.

First thing to do is to calibrate the accelerometer so you can subtract the zero offset and calculate acceleration in g.