The official currency of Gibraltar is the Gibraltar pound GIP, which is pegged to the British pound sterling at a 1:1 exchange rate. While the British pound sterling is legal tender in Gibraltar, and is accepted by all banks, government offices, and businesses, the Gibraltar pound is not legal tender in the UK.
While banks in the UK will exchange Gibraltar notes, they may charge a service charge for it. They are also highly unlikely to be accepted in any other country for exchange purposes, so unless you want to keep them as a souvenir it would be wise to spend them in Gibraltar.
Shops in Gibraltar will usually give you change in UK notes on request, if they have them. Any leftover Gibraltar pound notes at the end of your trip can be exchanged for UK pounds at par in any of the local banks but not at banks in the UK with no service charge.
If you find you have some Gibraltar coins left over then it is not such a big deal as they are identical in denomination, colour and size to UK coins. While they are not technically legal tender you are extremely unlikely to have such coins refused in a shop back in the UK as most people wouldn't even notice them. It is actually fairly common to get Gibraltar as well as many other UK dependencies and overseas regions coins in your change in the UK anyway.
Most shops in Gibraltar will accept US dollars and Euros. Bear in mind that shops will generally give you a more expensive rate of exchange than the numerous exchange offices and generally won't accept small change. Government offices, post offices and some payphones do not accept foreign currency, and will require you to pay in pounds.
Credit and debit cards are sometimes not accepted in some shops especially restaurants.