Water temperature and octopus size seem to have the biggest effect on lifespan. Most dwarf species will never see past 1 year of age; medium sized species that are best suited for aquariums will typically live 12-18 months, again, as Animal Mother stated, you may get 24 months from the octopus if you are lucky; Larger octopuses (such as GPO) can live anywhere from 2-5 years, with very few exceeding that number. Unless you get an octopus that was hatched in captivity, you shouldn't be expecting to have your pet for a large amount of time. The only way to tell the age of an octopus would be if they were hatched in captivity. Guesses can be made, but accuracy is low. Animals collected from the wild will typically be near senscense, meaning the end of their life.
Cold water species will live longer than tropical, however those will be difficult to find. Bimacs kept with a chiller set to ~60 degrees fahrenheit can live up to two years. Keeping them at room temperature or tropical temperatures will most likely cause you to have less time with them. It hasn't been tested (to my knowledge) the relationship between how long the octopus will live and temperature; I do know of one person that kept several octopuses in different temperatures throughout their lifespan and the survival rate was never lower due to lower temperatures.
If you do receive a tropical species, please don't set the temperature below 72.
Hope I helped.