Start by cleaning the trim. This can be as simple as wiping down the wood work with mild soap and water or wiping it with a deglosser/prepping compound like Paso. Paso is the best as it deep cleans and chemically etches the paint, but it smells bad.
Now lightly sand the areas needing the repair. Use 80 grit sand paper or a course sanding sponge. This will remove any loose paint and roughen the area for patching.
You have a few different choices for patching compounds; light weight spackling paste, regular interior/exterior spackling paste, wood dough, Bondo auto body filler or spot putty. The best is the auto body products like Bondo and spot putty. These dry hard and can produce a very permanent repair but are difficult to use. The other side of this spectrum is spackling paste with the best being regular interior/exterior. Spackling paste is easy to use and sands easily.
Fill the gouges and dents with your patching compound then sand it smooth with the surface after it dries. All repaired areas will need a little primer before painting.
All of this work is the "best" way to prepare your wood trim for painting. It will provide a nice smooth surface for painting. The amount of work you do depends of the outcome you want. If you're pressed for time, concentrate on the most damaged areas.