Floquet approach to Z2 lattice gauge theories with ultracold atoms in optical lattices