Iraq’s parliament has elected Nizar Amedi as president, ending months of political paralysis and shifting focus to the formation of a new government.