This paper deals with hybrid modelling and control of cyber-physical systems, which are part of a recently introduced phenomenon Industry 4.0. As a case study we look at a hydraulic system with hybrid dynamics represented by coupled tanks. The dynamical system contains two discrete modes, specifically with and without interaction. The nonlinear hybrid system was modelled using s-functions and then its linear description was created in the discrete PWA representation with the help of HYSDEL modelling framework. Both s-functions and HYSDEL are part of MATLAB/Simulink environment. After validation of the discrete PWA representation in comparison with the nonlinear hybrid system, LQR synthesis with reference trajectory tracking was designed for both discrete modes. Subsequently optimal control designed on the linear hybrid system in the discrete PWA representation was verified on the nonlinear hybrid system.