In very large wind farms, the vertical interaction with the atmospheric boundary layer plays an important role, i.e. the total energy extraction is governed by the vertical transport of kinetic energy from higher regions in the boundary layer towards the turbine level. In the current study, we investigate optimal control of wind-farm boundary layers, considering the individual wind turbines as flow actuators, whose energy extraction can be dynamically regulated in time so as to optimally influence the flow field and the vertical energy transport. To this end, we use large-eddy simulations of a fully developed pressure-driven wind-farm boundary layer in a receding-horizon optimal control framework. For the optimization of the wind-turbine controls, a conjugate-gradient optimization method is used in combination with adjoint large-eddy simulations for the determination of the gradients of the cost functional. In a first control study, wind-farm energy extraction is optimized in an aligned wind farm. Results are accumulated over one hour of operation. We find that the energy extraction is increased by 16 % compared to the uncontrolled reference. This is directly related to an increase of the vertical fluxes of energy towards the wind turbines, and vertical shear stresses increase considerably. A further analysis, decomposing the total stresses into dispersive and Reynolds stresses, shows that the dispersive stresses increase drastically, and that the Reynolds stresses decrease on average, but increase in the wake region, leading to better wake recovery. We further observe also that turbulent dissipation levels in the boundary layer increase, and overall the outer layer of the boundary layer enters into a transient decelerating regime, while the inner layer and the turbine region attain a new statistically steady equilibrium within approximately one wind-farm through-flow time. Two additional optimal control cases study penalization of turbulent dissipation. For the current wind-farm geometry, it is found that the ratio between wind-farm energy extraction and turbulent boundary-layer dissipation remains roughly around 70 %, but can be slightly increased by a few per cent by penalizing the dissipation in the optimization objective. For a pressure-driven boundary layer in equilibrium, we estimate that such a shift can lead to an increase in wind-farm energy extraction of 6 %.