Best approximation in the mean by analytic and harmonic functions