My understanding is that the cost function is not really part of the calculation of coefficients in OLS, which can be derived in close form. However, it comes into play when regularization is introduced.
Differentiating the cost function with respect to the estimated coefficients is the method.
The cost function would be generally expressed as:
$$J(\hat \beta)= (y - {\bf X}\hat \beta)^T(y- {\bf{X} \hat \beta})= \displaystyle \sum_{i=1}^n (y_i - x_i^T\hat \beta)^2= \sum_{i=1}^n(y_i - \hat y_i)^2$$
Expanding the quadratic in matrix notation:
$$J(\hat \beta)= (y - {\bf X}\hat \beta)^T(y- {{\bf X} \hat \beta})= y^Ty + \color{blue}{\hat \beta^T\,X^TX\,\hat \beta} - 2y^TX\hat \beta$$
The term in blue is the only non-scalar term remaining, and I presume that if setting the equation equal to zero to calculate the coefficients with a minimum cost function has to work, $\color{blue}{\hat \beta^T\,X^TX\,\hat \beta}$ must be positive definite. I know that $\color{blue}{X^TX}$ is positive semidefinite. But if all the above statements are correct, how can we proof that $\color{blue}{\hat \beta^T\,X^TX\,\hat \beta}$ is positive definite?