What terms can be written into an agreement to make sure that a product developed with an outside company meets quality standards such as uptime, speed, etc?
The terms don't really matter unless you have a big legal budget to fight it out in court. More useful is to have staged payments and withhold those payments if you aren't satisfied.
As an example, you might specify that 50% is paid at "feature complete", 25% at completion and the remaining 25% some time after delivery, when the quality can be properly judged.
Of course, some people may not like these terms, but at least you will have a bargaining stick if things go wrong. In the end, it is all about trust on both sides, so if you can find someone via a recommendation, then that is always a good thing.
See, outsourcing is not bad, however it is not a silver bullet either. You can not just hand over the specs to your developer and hope that everything will turn out good.
You need to be participating in many activities which are involved in software development. Now you have mentioned two points:
Apart from these two points for code quality there are several tools which can do static/dynamic analysis and can give you the report of quality of code.
There are so many other tools and best practices guidelines which can help you to identify a fake guy and a good guy.