Don't put them in the washing machine under any circumstances, and don't use bleach either - it destroys the materials and makes the sole brittle. Water that's too hot isn't ideal either.
What really works: scrub your white sneakers with a mixture of warm water, a few drops of dish soap, and a soft brush (an old toothbrush works, but a shoe brush is better). A toothbrush alone doesn't have enough power. The important thing is to move the brush in circular motions, not just rub the surface lightly. For stubborn stains, you can also try a rubber eraser - sounds weird, but it works surprisingly well on canvas and leather. Baking soda mixed with a bit of water makes a good paste for white spots too.
After scrubbing, rinse with clear water and then air dry - not in the sun, or they'll turn yellowish. Stuffing them with white paper helps keep the shape. If your sneakers keep turning gray, just try cleaning them more often before the dirt sets in. Some people swear by special shoe sprays for protection, but honestly, good cleaning is enough.