Helmets good for commuting will generally be tougher than those designed for racing, so scuffs and scrapes shouldn't affect their safety. But if you drop or dent your helmet or it gets gouged, its structure could be affected and it might not protect you in a crash, so you should replace it.
If you do have an accident while wearing your helmet, that also means that it should be replaced, even if damage is not visible. Some helmet makers offer a discount on a replacement for a helmet that has been damaged, so read the small print to see if yours is covered.
Cycling helmets have a finite lifespan, as the EPS foam tends to degrade over time with use and exposure to sunlight. Extreme temperatures will also affect longevity, so don't leave your helmet in a window or in a car on a hot day.
Manufacturers recommend that you should replace your helmet after around three to five years.