Hi there what you need is lagrange multipliers for constrained minimisation. It works like this,

Now we want to minimise this subject to or .

We proceed by writing a function of alpha and beta (the paramters you want to change to minimse the variance of X, but we also introduce another parameter that multiplies the sum to zero constraint. Thus we want to minimise

.

We partially differentiate this function w.r.t each parameter and set each partial derivative equal to zero. This gives;

Setting the first two partial derivatives equal we get

Substituting into this expression for beta and re-arranging for alpha gives the result for alpha. Repeating the same steps but isolating beta gives the beta result.

Lagrange multipliers and constrained minimisation crop up often in stats problems. I hope this helps!