What I normally do with a chain is clean it every couple of months with a degreaser while leaving it on the bike. And once every year (or somewhat longer) I totally replace the chain, they are not the expensive (about 20 dollars or so?).

And yes, the sort of grease you use on the chain also helps to keep it from getting filled with dirt.