Time-Dependent Adjoint-Based Optimization Of Photonic Crystals And Metamaterials Using A Stabilized Finite Element Method