You can do that (estimate the magnitudes via regression), but you can actually estimate the magnitudes and the phases using regression, so it will still work when the phases are unknown, and it will work in the presence of noise in $y$ (in the sense at least that you can still estimate those coefficients, though themselves with some noise).
Specifically, rather than just fitting $\cos$ terms, if you fit both $\sin$ and $\cos$ terms, you can obtain both magnitude and phase.
Using trigonometric terms in this way is discussed herehere, which discusses fitting several harmonics of the period, as well as estimation of both phase and amplitude.
If frequency is also unknown you have a nonlinear problem and in that case you would use other approaches (such as nonlinear regression discussed in another answer to the first question linked here).