To block everything, set DROP as a policy. You can also use REJECT, which means that the party that tries to connect will receive an ICMP packet as a reply.
To open 9050 and 9051, add two rules. I don't know whether Tor uses TCP or UDP, so adapt it if necessary.
Code:
iptables -P INPUT DROP
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 9050 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 9051 -j ACCEPT
The two ACCEPT lines can also be fused into one by specifying a port range.