I noted that $9,40$ and $41$ are pythagorean triple, i.e $9^2+40^2=41^2$. This fact can be used to solve the question easily. I'll show the solution for the general case:
$a\cos\theta+b\sin\theta=c,$ given that $a^2+b^2=c^2$
$$a\cos\theta+b\sin\theta=c$$
$$b\sin\theta=c-a\cos\theta$$
Squaring both the sides:
$$b^2\sin^2\theta=c^2+a^2\cos^2\theta-2ca\cos\theta$$
Substituting $c^2$ with $a^2+b^2$ gives:
$$b^2\sin^2\theta=a^2+b^2+a^2\cos^2\theta-2ca\cos\theta$$
$$a^2+b^2\cos^2\theta+a^2\cos^2\theta-2ca\cos\theta=0$$
$$a^2+(a^2+b^2)\cos^2\theta-2ca\cos\theta=0$$
$$a^2+(c\cos\theta)^2-2a(c\cos\theta)=0$$
$$(a-c\cos\theta)^2=0$$
$$\cos\theta=\dfrac{a}{c}$$
Substituting $c=41$ and $a=40$ will give the solution of the particular equation discussed in the question.
An interesting thing is that $\sin\theta=\sqrt{1-\dfrac{a^2}{c^2}}=\dfrac{b}{c}, $ , i.e the equation actually belongs to a right angled triangle having $a$ as its base, $b$ as its prependicular and $c$ as its hypotenuse.
There is another method in which we divide both sides of the equation with $\sqrt{a^2+b^2}$ and then use the identity:
$\sin (A+B)=\sin A \cos B+\cos A \cos B$
This method will give the same results.
Converse
Consider a right angled triangle having base $a$, perpendicular $b$ and hypotenuse $c$. We have:
$$\cos\theta=\dfrac{a}{c}\ \ \text{and}\ \ \ \sin\theta=\dfrac{b}{c}$$
$$\implies a=c\cos\theta \ \ \ \text{and}\ \ \ b=c\sin\theta$$
By the pythagoras theorem:
$$a^2+b^2=c^2 $$
$$\implies\ c^2\cos^2\theta+c^2\sin^2\theta=c^2$$
$$\implies c\cos\theta \cdot c\cos\theta + c\sin\theta \cdot c\sin\theta=c^2$$
$$\implies a\cos\theta+b\sin\theta=c$$