Very helpful, considering the thread title is "De Moivre's theorem".
OP: we know that z = cos 3x + i sin 3x = (cos x + i sin x)^3. Expand that right hand side by the binomial expansion, and you get z = cos 3x + i sin 3x = a + ib for some functions a and b. Then you know that tan 3x = Im(z) / Re(z) from the first equality, so do the same to the last equality...
Equate coefficients. We know that cos nx + i sin nx = (cos x + isinx)^n Then we multiply out the right hand side To get cos nx = ... we ignore the terms of the expansion with i in them To get sin nx = ... we ignore the terms of the expansion without i in them.