How to get Gold and Elixir
Clash of Clans Guide
If you are running low on Gold or Elixir you can use Gems to purchase more of it, but the easy way is to use Gold Mines and Elixir Collectors to do so. The more you upgrade them, assuming you have enough storage to hold it all, the more of these two resources you will get coming in.
Gold is used mainly to upgrade your Town Hall, Walls and other defensive structures - it also allows you to build Walls very quickly, which can get quite expensive. Elixir is similar in that it is used to upgrade most structures in the game.