The wisps serve two purposes, one in the story and one in the gameplay.
Narratively, Eggman has been capturing them to drain their power and turn them into Nega Wisps, which is what Sonic sets out to undo. Mechanically, each wisp colour grants Sonic a different ability — the rocket boost being the most famous — so they double as the game's power-up system.