Generally, if you want the cleanest lines (or to create the illusion of a straight edge), you can use tape (frog or 3M blue) to mask. Plan to 'dominate' onto the surface not painted by about 1/16"; this will allow you to choose the order in which you do everything, because you will create a straight line on the edge of the color, no matter what.
However, the best tape for masking is expensive, and the tape can add time to your budget. If you can remove the trim, fine. If not, the process can and will usually be:
1) Ceiling first, if you actually do it, to avoid splattering
2) After trim is stripped, it can be primed and painted anytime, if you remove it. In addition to the order flexibility, you will not have to mask any of it (although most pros will caulk the trim once on, cut over the bead onto the wall before it gets its turn, and use the tape to create the line.
3) The temptation for some people in cutting walls along ceilings is to create wide cut lines, 4 inches or more. Depending on how proficient you are at smoothing out brush marks, and how high your ceiling is, this can either help you avoid hitting your ceiling or create ugly banding around the top of your wall. You can wear gloves and use the ceiling as a stabilizer for your cutting hand, keeping your cuts about two inches wide; three at absolute most.
4) Roll each wall as you cut inside the corners and along the ceiling. Some people will actually roll a wall one coat before any cutting, as tight along the ceiling and walls as possible, helping greatly with step (3), as it minimizes the cutting necessary (some painters will get within 1/2" of the ceiling, but don't try to be a hero, especially if textured or freshly painted).
5) The important thing to remember is that the final step on the second coat should be a finishing roll (after spreading paint as evenly as possible, gently and lightly run your roller sleeve top to bottom in a straight line with even pressure, overlapping each about 4-6 inches).
There are many ways to do it obviously (especially if you tape everything), but the way I described appears to be most common in my area. You can caulk and freehand cut the baseboard on the wall and get away with up to a 1/4" of baseboard color on the wall without anyone really noticing, but if you want hairline crack-free lines on the window/door trim, plan to caulk and mask the wall with delicate surface frog tape using the 1/16" domination rule I described above.
Just out of curiosity, why do you want to strip the trim? If you do remove the trim, consider a de-gloss/buff step, and use a can of KILZ or Bullseye/BIN 123 to base-coat; you'll solve 99% of all adhesion problems. If you choose to leave the trim on, just get the non-spray versions (unless you want to do lots of masking beyond just tape).