I haven't implemented one myself, but Kalman filters are frequently used for this. Search HN's history to find several (presumably) good introductions.
Complementary filters works well enough and is very simple to implement even if you're a noob (e.g., high pass on accelerometer and low pass on gyro).
Madgwick, S. O., Harrison, A. J., & Vaidyanathan, R. (2011). Estimation of imu and marg orientation using a gradient descent algorithm. In Proceedings of the IEEE International Conference on Rehabilitation Robotics