Variational control approach to energy extraction from a fluid flow