The blue background indicates that it is an iMessage sent via the Internet by Apple (free), the green background means it is a regular text/MMS sent over the cellular network and is using up your message allotment through your carrier.
The only way iMessage can be used is if it is between two iDevices that both have iMessage turned on in Settings/Messages. As long as you have two phones with iMessage enabled AND they both have Internet access, the text or MMS will be automatically sent via iMessage. One of the advantages of iMessage (other than being free) is you can also set it to deliver Receive and Read receipts to those who have sent you an iMessage. You will find those settings in the same place you turn iMessage on or off.
It's blue if sent to to an iPhone, iPad or iPod Touch and green if sent to a non-Apple phone. If Apple's iMessages server is down or the person has a poor Internet connection, it will fall back to sending it as a regular text message, which is green.