(How) can I prevent pasta water from boiling over with the lid closed? I always cook pasta with the lid of the pot open, because otherwise foam starts to build up and eventually boils over, maikng a huge mess. I would prefer to keep the lid on for energy saving purposes. Is this possible at all? What makes the foam build up, why does it not when the lid is open?
You can use a larger pot. I always use my 12 qt stock pot to boil pasta in. I fill it anywhere from 1/3 to 2/3 full and have no problems with boil over. I too always use it with the lid on. Granted, you're going to use more energy to heat a larger quantity of water, but meh. I'd bet that your refrigerator and A/C use gobs more energy than your range.

As to why it happens? I'm speculating here, but maybe it's the back pressure on the foam bubbles when the lid is on. With the lid off the bubbles can expand rapidly, and break. With the lid on, there is slight back pressure which could restrict the bubbles ability to expand as quickly.