There is a lot of truth in all other answers so far. This being a somewhat complex matter, but considering it's perhaps the biggest operational cost of a bicycle (the other would be new tubes), I want to offer my cents.
First of all: The chain has ALL responsibility for the wearing of the drivetrain. If you take new cogs and rings with an old chain, the drivetrain will be destroyed VERY quickly. But taking worn-out cogs and rings, and using them with a "theoretical perfect chain" which wouldn't wear out, would actually make the cogs and rings wear BACK to good: the teeth would be progressively thinner, but their profile ramp would be fine.
This happens because a worn chain, having a greater distance between pins, touches "higher" on the teeth and creates a ramp (sharktooth) profile, causing a new chain to skip. A new chain, in the other hand, always touches the bottom of the teeth, then wearing them out by "thinning", instead of "ramping"
An excellent text about chain wear and wear measurement can be found here:
http://pardo.net/bike/pic/fail-004/000.html
The problem is: usually you can ride sligtlhy worn cog with slightly worn chain, but sometimes you cannot ride wlightly worn cog with NEW chain, because the chain skips. It depends how much the cog is worn. The same might happen with chainrings, but it is much more rare and usually happens only when the bike is seriously neglected (and seriously ridden!)
So, answering your question, I propose this "plan" to extract every kilometer a drivetrain can give, with the least money spent. Some tips might require boring manual labor, so you should measure this cost, too. In the other hand, I feel "wrong" throwing away a part which I know is still usable. The planet thanks.
- Replace the chain for a new one. Always replace chain first. Never replace anything else before putting a new chain. Chain must be new. There's no need to remove the "glue" it comes with, neither add another lube (this is objectionable, but I think a bit of initial wear and settling - if any - of the new components is more good than harm).
- If the chain skips in the rear, you can take the following approaches, in that order:
- Ride slowly at first, and wait for the said settling down of components. This means the old cog should wear a bit and regain its proper shape. This requires a lot of patience, sometimes.
- If you have a not-so-worn-out chain (read below), you can install it and ride with it for a while. Then you can install the new one.
- If not number 1 or 2, replace the cogs and rest your mind.
- Disregarding the rear cogs, if the front chainrings skip, first and foremost REGRET A LOT, then do one of the following approaches, in that order:
- Flip the ring inside out if possible, or if you don't want to perform the (preferrable) next step.
- Disassemble the ring, take a round file, and remove a bit of the base of each tooth, yelding the proper round base and vertical tooth end (and not the ugly sawtooth shape it has now it's worn-to-the-core). This sounds odd, but works like a charm, is easy to do. The same approach might help for the rear cogs, but requires Heavy Wizardry on Metal Handcrafting (I saved a lot of expensive clusters this way, but my last attempts were not successful. I gave up buying expensive clusters anyway, but my old failed clusters are hidden here, waiting for advances in technology to appear).
- Spend the bucks and sigh in relief.
Not to say everything on the subject hasn't been said, let's suppose you finally reached the dynamic equilibrium of replacing a chain each time it stretches by X per cent (it's not good measuring on KM ridden. It is always adviseable to measure distance between pins. The distance between 24 pins should be 12 inches.)
This would give you an absurdly long-lasting cogset and crankset. If you only ride dry on-road, 30 thousand kilometers are expected from them. BUT you end up with A LOT of chains which would look pretty much as new. And here comes the trick:
If you really want to suck every possible cheapest kilometer from a drivetrain, at some moment you just stop buying new chains and START TO USE THE SAME (NOT SO) OLD CHAINS AGAIN.
For example: if you replaced chains five times when they were, say, 1% stretched, you (still should) have five chains 1% stretched, and a "1% stretch compatible" drivetrain. Then you use the first chain until it is a bit more stretched, say, 2%, and replace for another 1% chain, until all the five chains AND the drivetrain are together at 2%. Get the idea?
This way, after many, many, MANY kilometers you'll end up with a crappy drivetrain with teeth so thin you could make ninja weapons with them. But that would be after destroying 5 chains, not one, and having made FIVE TIMES more distance for the buck.
Of course, if the process is made with more chains, you get each time more kilometers per buck, with not so much work or patience required. Only an unusual dose of discipline.
Hope it helps