Gene circuits that control metabolism should restore metabolic functions upon environmental changes. Whether gene networks are capable of steering metabolism to optimal states is an open question. Here we present a method to identify such optimal gene networks. We show that metabolic network optimisation over a range of environments results in an input-output relationship for the gene network that guarantees optimal metabolic states. Optimal control is possible if the gene network can achieve this input-output relationship. We illustrate our approach with the best-studied regulatory network in yeast, the galactose network. We find that over the entire range of external galactose concentrations, the regulatory network is able to optimally steer galactose metabolism. Only a few gene network parameters affect this optimal regulation. The other parameters can be tuned independently for optimisation of other functions, such as fast and low-noise gene expression. This study highlights gene network plasticity, evolvability, and modular functionality.