Smoothing torque and speed

In engines, power is only produced during the power stroke, producing a fluctuating torque. Without a flywheel this would result in a jerky motion in the vehicle. Adding a flywheel to the crankshaft (the part that rotates due to the motion of the pistons in the cylinders) smooths out the rotation due to its inertia - it takes more time to speed up and slow down, so the motion is less jerky.

Regenerative braking

A flywheel can be used in cars as a store of kinetic energy - when the car needs to brake, this is accomplished by transferring rotational kinetic energy from the wheels to a flywheel, slowing the wheels and hence the car. Then when accelerating this rotational KE is transferred back from the flywheel to the wheels. This helps to conserve fuel, compared to traditional braking in which the KE lost is all dissipated as heat.