Well, you have to start leveling a pokemon with EVs in mind. Your pokemon will collect them normally whether you like it or not, so you have to start with it while it's still pure (freshly caught or hatched). A good place to train for special attack is the abandoned mansion in the Eterna Woods. Ghost pokemon there give EVs in Special Attack (1 for Ghastly, 2 for Haunter, and 3 for Gengar).
EVs cap at 255 for a stat, and you can only collect 510 total. After that, your pokemon no longer gains them. Realistically, you should stop at 252 EVs in a stat, since it takes 4 to gain on stat point, and the extra 3 won't give you anything since stats are all integers rounded down in Pokemon. It's most effective to train your pokemon in two stats. Increase them further by breeding for better IVs (a value anywhere from 0-31) and beneficial natures (for the 10% stat bonuses). It's a big pain, really, but it's necessary if you really plan to compete online.