Mott insulator states of ultracold atoms in optical resonators