Are you certain that the definitions for the pitch and roll angles are exactly the same as defined in the AN4248 application note? That would include the definition of a positive rotation.
You might be better off just using the corrected accelerometer and magnetometer readings, and implementing the code described in AN4248 (it is available for download).