Set Acosx + Bsinx = Csin(x+arctanD)
=C(sinx * cos(arctanD) + cosx * sin(arctanD) ) <sin of the sum of two angles identity>
draw pretty right triangle, label one leg D, the other leg 1, such that the tangent of one of the angles is D. Pythagorean theoremize the triangle to get the hypotenuse = sqrt(1+D²)
From there, the cosD = 1/sqrt(1+D²) and sinD = D/sqrt(1+D²)
Fill these into the 2nd line above:
=C[sinx / sqrt(1+D²) + Dcosx / sqrt(1+D²)
shuffle things around a bit, and pair up the cosx term on the left to the cosx term on the right;
the sinx term on the left, and the sinx term on the right.
Thus, A must = CD/sqrt(1+D²) and B = C/sqrt(1+D²)
Hope that helps; I seem to recall seeing something like this about 20 years ago, but haven't seen it since. Hopefully my derivation isn't off; I don't have a pen or pencil around to do it on paper first.
After that point, I assume you simply solve for C and D (2 equations, 2 unknowns) - should be simple.
And, hopefully there are no mistakes above; I didn't even stop to ponder any domain issues or anything of the sort. And, I didn't bother solving for C and D, so once I saw those solutions, it might point to a simpler derivation.