Systematic Foundations of Optimal Control with Photonic and Chemical Reagents