From the Super Mario Wiki
Butterflies are flying insects found in the Real World that appear in many games in Mario series and usually do so in groups. There are also many creatures that have a similar appearance to a butterfly.
Butterflies made their first appearance in Super Mario World 2: Yoshi's Island, and make a return in the game's remake, Yoshi's Island: Super Mario Advance 3. In these two installments of the Yoshi series, the butterflies only act as scenery elements. The original game also marks the debut of Flutters, which are basically winged Wigglers that resemble butterflies.
In Yoshi's Story, butterflies reappear as part of the scenery, however numerous butterfly sub-species such as the Teehee Butterfly and the Power Bee (known as Happiness Butterfly in Japan) appear as edible health restoring creatures.
Super Mario series
In Super Mario 64 and Super Mario 64 DS, there are a few stages (as well as outside the Princess Peach's Castle) where butterflies fly around. When Mario punches or goes near one, one of two things will happen: the butterfly will either turn into a 1-Up Mushroom or become a black sphere and chase Mario until it hits him or hits something in its way; in either situation, it explodes.  In this game, butterflies are violet with white spots on their wings.
In Super Mario Sunshine, Yoshi could eat certain types of butterflies to get different items. Yellow Butterflies yield regular coins, blue Butterflies yield Blue Coins, and green Butterflies yield 1-Up Mushrooms. In this game, butterflies are usually found fluttering around in groups, and are rarely by themselves like in Super Mario 64.
In Super Mario Galaxy, butterflies are seen throughout various Galaxies. Even though they are used mainly for decoration, the player can collect a single Star Bit per butterfly by pointing the Star Cursor at the butterfly and moving the cursor around while still touching it, although this does not work while Mario or Luigi are on the Comet Observatory.
In Super Mario Galaxy 2, a number of shimmering golden butterflies appear on the Starting Planet in the Sky Station Galaxy (three also appear on the Peewee Geo Planet later in the galaxy), but only while Co-Star Mode is active. The player can use the Co-Star Luma to spin the butterflies in the same way as they would any other object. When spun, each butterfly releases three Star Bits each, after which they disappear. They also disappear the second that Co-Star mode is deactivated, though when it is used again, they return. If spun by the Co-Star Luma, they are gone for good. These golden butterflies also appear on the Earth Planet, the Yoshi Tower Planet, the Fossil Planet, the Solar System Planet, and the Cone Planet in the Yoshi Star Galaxy. A different variety of butterfly also appears on the Stone Mountains Planet in the Fluffy Bluff Galaxy. These particular butterflies are purple which are present for decoration only.
Butterflies also appear in some levels of Super Mario 3D Land. These particular butterflies have different colors, and cannot be affected by the player.
Super Mario RPG: Legend of the Seven Stars
In Super Mario RPG: Legend of the Seven Stars, butterflies first appear in the opening with Princess Peach right before she is kidnapped. They later appear as part of the scenery in some areas of the game.
Paper Mario series
Mario Party series
They later appear in Mario Party 4 in the mini-game Butterfly Blitz. They have a small but major role; they are worth points when characters catch them. There are three kinds of butterflies that give players points to win; yellow butterflies are worth one point, red butterflies are worth two points, and blue butterflies are worth three points.
A Butterfly also made a very brief appearance in the Mario Party 8 mini-game "At the Chomp Wash". When a Chain Chomp sees it, the Chain Chomp attempts to chase it, which in turn knocks over several buckets of paint.
Names in other languages