Empirical variance minimization with applications in variance reduction and optimal control