At the highest level, the coefficients are a function of minimizing the sum of square of the residuals. Next, write down these equations while paying careful attention to what is a residual. To go further, consider the following:
1. Write the minimization goal (ideally in linear algebraic (matrix) notation) of minimizing the sum of squares of the residuals given a linear regression model.
2. Solve the minimization equation by illustrating that the sum of square of the residuals is a convex function, which can be differentiated and the coefficients can be derived by setting the differentiation to 0 and solving that equation.
3. Describe that the complexity of solving the linear algebra based solution in #2 is of polynomial time and a more common solution is by observing that the equation is convex and hence numerical algorithms such as gradient descent may be much more efficient.