How is it that $\tan(A +B) = \frac{\tan A + \tan B}{1-\tan A\tan B}$ for all angles, even though the derivation holds only for $\cos A\cos B\neq 0$?

You can think it like this way: If either cos(A) or cos(B) is zero, then we may take its limit of RHS and the equality makes sense.


Note that $$\tan(A +B) = \frac{\tan A + \tan B}{1-\tan A\tan B}$$ holds only if both $(i)\space A\ne \frac{\pi}{2}+k\pi$ and $(ii)\space B\ne \frac{\pi}{2}+l\pi$ for all $k,l\in\mathbb{Z}$ are satisfied. Otherwise, at least one of the values $\tan A$ or $\tan B$ does not exist since $\tan x=\frac{\sin x}{\cos x}$ whilst the zeros of cosine are of the aforementioned form.

The inconvenient case, though, one could simplify directly. Suppose $(i)$ holds, then $$ \tan(A+B)= \tan\left(\frac{\pi}{2}+k\pi+B\right)\stackrel{\text{periodicity}}{=}\tan\left(\frac{\pi}{2}+B \right) \stackrel{\text{trig. identity}}{=}-\cot(B).$$

Assured of ability to handle the tangent of sum when $(i)$ or $(ii)$ is true, one can assume that both $\cos A$ and $\cos B$ are not $0$ and divide by it in order to obtain the discussed expression.