The most important thing styrofoam coolers have going for them is the ice inside. In order to melt, a block of ice needs to absorb a considerable amount of energy. The ice and ice water will stay at freezing temperature until the ice has nearly completely melted, so even without the insulation of the styrofoam, a cooler could probably keep your food cool for several hours.
Convection and Conduction
An ice cooler mainly has to prevent two kinds of warming: convection and conduction. Convection occurs when currents of a fluid such as air move heat from a hotter object to a cooler one. Conduction occurs when heat moves directly from a warmer object to an adjacent colder one. Coolers are designed to minimize both kinds of heating.
Warmer molecules are moving faster than cooler ones. When a warm molecule bumps into a cold one, some of that motion is transferred, making the cold molecule move a little faster (i.e., get a little warmer.) Air is an extremely poor conductor because the molecules are spread out. Styrofoam has lots of tiny air bubbles inside of it. The heat can not flow efficiently through the material from outside to inside, since all of the air bubbles slow it down. Air does leak through, but it does so very slowly, keeping things cool inside.
When a cooler is opened, convection currents immediately take their toll. Warm air blows in, melting the ice inside and warming up the cooler. As long as styrofoam coolers are kept closed most of the time, convection does little to warm them up. Air currents can warm the surface of the cooler, but this warmth takes a long time to get inside because of the insulating properties of the styrofoam.