I've read that 18V li-ion batteries are over 18V when charged. How do I make sure this won't harm my motor or anything else?
You don't tell us anything about the motor, but brushed motors are pretty tough. Brushless motors tend to be even tougher, but their controllers may be another matter.

A moderate overvoltage won't normally kill a motor, just slightly overspeed it. Now at hundreds of volts, you have to worry about exceeding the insulation breakdown voltage, but not at 21V. And if it's a particularly high performance motor, that overspeed can overstress bearings or add to brush wear, or destroy the rotor through centrifugal force, but otherwise it's unlikely to do any harm, unless the motor is heavily loaded. 

Now in combination  with a heavily loaded motor, that's a different matter. Loading a motor enough to slow it down, makes it draw a high current, which dissipates a lot of power in its winding resistance, and the high current can also burn out the brushes, melt the commutator, etc. If the motor's this heavily loaded, then the overvoltage supplies excess current, resulting in more heat and more damage.

So, don't do that.

If the motor's lightly loaded, (determine that by measurisg its current) it'll probably be fine.

And if you're still worried, limit the PWM controller to 80% duty cycle when the battery is fresh.