Let's say Costa Rica springs a surprise and beats Italy 3-1, and the last game between Italy and Uruguay ends in a draw. The FIFA Organizing Committee will actually draw lots to determine the other qualifying team in this scenario, given Italy and Uruguay would be tied in terms of points, goal difference, goals scored, head to head points, head to head goal difference and head to head goals scored.
http://www.conmebol.com/en/content/tie-breaker-rules-group-stage-2014-world-cup-brazil
Here is the rule for the ranking of the teams in the Group Stage of the World Cup, from Article 41 of the Regulations, 2014 FIFA World Cup Brazil
COMPETITION
The league format shall be used: each team playing one match against each of the other teams in the same group, with three points for a win, one point for a draw and none for a defeat.
The ranking of each team in each group shall be determined as follows:
a) greatest number of points obtained in all group matches;
b) goal difference in all group matches;
c) greatest number of goals scored in all group matches.
If two or more teams are equal on the basis of the above three criteria, their rankings shall be determined as follows:
d) greatest number of points obtained in the group matches between the teams concerned;
e) goal difference resulting from the group matches between the teams concerned;
f) greater number of goals scored in all group matches between the teams concerned;
g) drawing of lots by the FIFA Organizing Committee.
The teams that qualify from the group stage will play the round of sixteen.