To communicate with the RPI from outside of the router you have to set a fixed ip , there are sites which do it for free if you use it not for business (like duckdns, noip).
The application in the pi to control the devices - this depends on the devices requirements.