They inflict no damage but can occasionally bump into the player, pushing them slightly. Iron Golems also attacks them. They can be trapped using an Empty Jar which will then turn into a Butterfly Jar. Using (left clicking) a Butterfly Jar will release the Butterfly.
Butterflies will despawn once the player has reached enough distance for the chunks to unload. This can be prevented by using a Name Tag on the Butterfly.