I also had this problem (plus very dark green poop) and it was related to dairy. So was the really bad diaper rash that DS had for the first couple months of his life.
Keep in mind that if you cut dairy out, you need to really watch ingredients as there is dairy in most processed foods.
Also, you may need to cut it out for as long as 3 weeks before you notice the change. It is a protein in the dairy that they are sensitive to - not lactose, as many people assume. That protein can persist in your body (thus in your milk) for over a week, then in their body for over a week. It took almost the full 3 weeks until I noticed a difference. No more diaper rash, etc. Now I sneak a bit of dairy in now and then to see what's happening, and it almost always results in green poop and a minor diaper rash...
There are a number of other foods that can create similar problems - soy, wheat, corn, nuts... I think there are 8 food groupings of likely candidates. It's on here somewhere - I've seen other people post the list previously.