A variational approach to quantum field theory