Standard OP_RETURN output is for attaching arbitrary data (e.g. a hash of some document). How do you use it - it's your problem. But you are encouraged to add this data as OP_RETURN output instead of, say, a 1 satoshi fake address output. This way the index of unspent outputs will not be cluttered with provably unspent outputs (my opinion: that does not matter, UTXO will grow huge anyway; we need other ways to optimize it).
For smart contracts there is an entire scripting language built-in. And there are some wiki pages on how you can build cool contracts with it:
https://en.bitcoin.it/wiki/Contracts