In the fight over immigration policy, the state and its municipal opponents are gearing up for a series of legal battles.