The paper addresses the issue of unified power flow controller (UPFC) modelling within the context of optimal power flow (OPF) solutions. The nonlinear optimisation problem is solved by Newton's method leading to highly robust iterative solutions even for cases of large-scale power networks, where hundreds of variables are to be optimised. It is shown in the paper that networks modified to include several UPFCs are solved with equal reliability. The UPFC model itself is very flexible, it allows the control of active and reactive powers and voltage magnitude simultaneously. It can also be set to control one or more of these parameters in any combination or to control none of them. Considerable progress has been achieved in UPFC modelling intended for conventional load flow studies but this is the first time that the more complex issue of UPFC modelling intended for OPF solutions has been addressed.