With the advent of quantum technologies, control issues are becoming increasingly important. In this article, we address the control in phase space under a global constraint provided by a minimal energy-like cost function and a local (in Fourier space) constraint resulting from a robustness criterion. The inverse engineering Lagrangian formalism developed here generalizes the one commonly used to describe the superoscillation phenomenon. It is applied to both non-dissipative and dissipative quantum mechanics, and extended to stochastic thermodynamics. Interestingly, our approach also allows to improve the sensing capabilities by an appropriate control of the system.