Ultimately its going to be down to how zealous you want to be.
When you think of cleaning a chain, you need to think of two things. First, there is the cleaning - getting off the dirt and lube that has caked itself onto the chain. Then, there is lubing the chain to make it run nicely, (As part of a lube you'd maybe give the chain a rub with a dry cloth to try and get surface crap off, but wouldn't be soaking it in degreaser).
When maintaining a chain, you wouldn't necessarily do both of these at the same time. You would lube the chain quite regularly, but most likely would clean the chain less frequently. You'd never clean the chain without also lubing it.
For frequency of lubing, the answer is "it depends". We all have different preferences. If its a bike that doesn't get ridden often, you'd maybe lube the chain before every ride. A commuter, ridden daily, you'd maybe lube every week or two.
Also, you need to recognise that there are (many) different types of lube, for different conditions. The viscosity varies a lot between them. So if you're putting a lightweight dry lube on your chain (which you might do in the summer), its going to be far less likely to muck up your chain than a gloopy wet weather lube.
So the answer to "when do I clean it?" is also "it depends".
Ideally you don't want any dirt on your chain. That would improve both smoothness and chain life. So the anal extreme is to clean and lube it after every ride.
But most probably you'd go through the "lube" process several times before you considered degreasing. And, as I say, the lube you use will determine likely you are to pick up crap off the road. A wet weather lube, for example, might be good at repelling water, but it's corresponding stickiness will also attract dirt.
If I were to stick my finger in the air I'd say that personally I give my chains a thorough degrease probably around 3 times a year (on the bikes that I ride regularly). But knowing when to do this, I judge this by looking how much crap is on it as I'm lubing it - it's certainly balanced toward winter/wet riding, but it's a judgement call.
Give the cogs a decent clean at the same time as you clean the chain, otherwise you're just going to transfer muck from on to the other.