First-principles study of the crystal and magnetic structures of multiferroic Cu2OCl2