A Physics-Informed Machine Learning Framework for Safe and Optimal Control of Autonomous Systems