PDEs and optimal control methods in MFG and multi-agent models