Delayed Onset Muscle Soreness (DOMS) is what you're referring to. The exact cause of DOMS is unknown (though it probably stems from damaged muscle membranes), but it can be prevented, or at least lessened by: 1) avoiding dramatic changes in training intensity or quantity, 2) maintaining muscle flexibility, and 3) incorporating some "eccentric" workouts into your training schedule. "Eccentric" refers to a contracting of the muscle while it's being stretched. Examples of eccentric training include running downhill and various hopping exercises (one leg hop, two leg hop, skipping, etc.) --basically, plyometric exercise. It's thought that the proactive benefit comes from muscle recruitment rather than any increased fiber strength.
Post exercise consumption of high glycemic index foods along with proteins will help as will drinking plenty of fluids (but not alcohol despite all traditions to the contrary). Post exercise ibuprofen will help decrease the perception of soreness, but taking it before won't, and it won't speed recovery. Mild stretching and exercise do speed recovery.