Motherwell set up a final-day shootout for second place with Aberdeen as they beat Inverness 2-1 in the Scottish Premiership.