https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses#How_to_create_Bitcoin_AddressI also have some PHP code here, if that helps:
https://gist.github.com/scintill/3549107 If you use the compressed version (shown in my code), it saves a few bytes in the blockchain when the balance in the address is spent, although not all clients can import the private key (for example, I just learned Electrum doesn't.) If you know Javascript, the code at bitaddress.org might help too. Casascius' utility (below) does it in C#.
When you get something working, I suggest using something like bitaddress.org or
Casascius' Bitcoin Address Utility to ensure your keypairs are valid.