Peak shaving applications provided by energy storage systems enhance the utilization of existing grid infrastructure to accommodate the increased penetration of renewable energy sources. This work investigates the provision of peak shaving services from a flywheel energy storage system installed in a transformer substation. A lexicographic optimization scheme is formulated to define the flywheel power set-points by minimizing the transformer power limit violations and the flywheel energy losses. Convex functions that represent the flywheel power losses and its maximum power are derived and integrated in the proposed scheme. A two-level hierarchical control framework is introduced to operate the transformer-flywheel-system in a way that handles prediction errors and modelling inaccuracies. At the higher level, a model predictive controller is developed that solves the lexicographic optimization scheme using linear programming. At the lower-level, a secondary controller corrects the power set-points of the model predictive controller using realtime measurements. A software platform has been developed for integrating the proposed controllers in an experimental setup to test their effectiveness in a realistic testbed setting, and the flywheel system characteristics are experimentally identified. Simulation and experimental results validate and verify the modelling, identification, control and operation of a real flywheel system for peak shaving services.