Effort Values, often shortened to EVs, are a hardly-known game mechanic in the Pokémon series of games. Sometimes described as a "hidden stat", they are not so much a stat in the same sense as Attack, Defense, Sp. Attack, etc. are, but rather serve as a way for players to hone an individual Pokémon's stats in one direction or another. Previously, Pokémon breeders were some of the only people who even knew about EVs, if at all, but lately it's become an essential method for Pokémon enthusiasts everywhere to create stronger and more balanced teams.
What are EVs?
Perhaps it would be best to start basically. Let's say you are battling your friend, and you both send out a Camerupt, a Fire/Ground-type Pokémon with high Attack and Sp. Attack, but abysmal defensive stats. Both are at level 100, have the same nature, and (by incredible luck) have the very same Individual Values. Basically, they are exactly alike—or almost exactly.
But when the battle begins, your Camerupt is somehow faster than your opponent's. You use Earthquake, expecting to KO it in one hit due to Fire's weakness to Ground, and your speed advantage. However, the opponent Camerupt survives the attack, and afterwards also uses Earthquake. And even though both of your Pokémon are the same species, level and nature, the opponent's Camerupt is able to OHKO your Camerupt using the same move with no critical hits or stat-boosting moves.
Why does this happen, even though the two Pokémon are basically exactly the same? The difference comes in how they were raised; or in other words, their EVs are different. More specifically, the winning Camerupt was probably trained with close monitoring of the EVs it was accumulating in battle, while yours wasn't. Because its EVs were focused in certain areas, specifically the areas Camerupts are low in (Speed and Defense), it was able to not only stay in battle longer, but deal more damage.
Great. How do Pokémon earn EVs, then?
Your Pokémon earn EVs whether you're conscious of it or not. Every time it defeats another Pokémon, it will gain at least one EV towards at least one stat. Every time a Pokémon earns 4 EVs for one stat, the amount that stat increases upon levelling up increases by 1 point (called an Effort Point).
The type of EVs you gain though depend on the kind of Pokémon you're fighting. Every species has a set number and type of EVs that the opponent Pokémon will gain if it defeats it. For example, defeating a Zubat will give your Pokémon 1 EV in Speed; defeating a Heracross will give 2 EVs in Attack; etc. (You can look up the EVs given from any Pokémon on most online Pokédexes, such as the one at LegendaryPokemon.net).
Limitations on EVs
Now, there are of course limits to this. One could conceiveably have all stats at 999 with enough obsessive EV training if there weren't limits, but alas, that's not how it works.
For starters, a Pokémon can gain a maximum of 510 EVs only, no matter how they are distributed among the 5 stats. Once it hits 510, EV training is done, and it doesn't matter which Pokémon you fight after that. After that, one particular stat can have a maximum of 255 EVs only. So, you can't put all 510 EVs into one stat.
This means that Pokémon with full EVs can potentially have a total of 127 more points across its stats than one with no extra Effort Points at all. And any one stat can have a maximum gain of 63 Effort Points—a good advantage over a Pokémon trained with no concept of EVs.
Quick EV Training
Now, you're probably thinking, "What? I have to battle 255 Zubats to get 32 extra points in Speed?! That's not worth it." Don't worry, it's not that bad. The "vitamin" items—Protein, Carbos, HP Up, etc. -- give 10 EVs in whatever stat they increase, besides adding 1 point permanently to that stat.
You can give 10 of each kind of vitamin to a Pokémon before you can't give any more of that kind. So if you're lazy and you've got the bucks, you can easily max out a Pokémon's EVs instantly by giving it 10 of 5 types of vitamins, and 1 more in whatever type of vitamin you didn't give.
Another way to quickly gain EVs is through the use of an Exp. Share or Macho Brace, two types of Pokémon hold items. A Macho Brace will double the amount of EVs gained for each Pokémon defeated (4 Attack EVs will be gained from defeating a Heracross instead of 2, for example).
Exp. Share will give the Pokémon holding it half of the EXP given after the foe is defeated, whether it enters battle or not. But it'll also give the same amount of EVs that the defeating Pokémon gained to the Pokémon holding it. So, if a newly hatched, level 5 Eevee is holding Exp. Share, and a level 50 Lapras defeats a Heracross, both Lapras and Eevee will gain half the EXP AND 2 Attack EVs.
Important to note here that if you use an EV boosting item to kill a Pokémon to gain extra EVs, the boost WILL NOT transfer to a Pokémon that is holding an Exp. Share.
EVs and Rare Candies
As long as your Pokémon is still able to gain exp via battling (i.e.- it isn't level 100 yet), it doesn't matter when you use your Rare Candies. Everything balances out once the Pokémon hits level 100.