Optimal Design of Periodic Diffractive Structures