We flew into Baku on Aeroflot from Moscow (paid ticket) and out of Tbilisi on British Airways (award). We spent 12 days between Azerbaijan, Georgia and Armenia. You can go overland to either Armenia or Azerbaijan from Iran, there are several weekly buses from Tehran to Yerevan (30 hrs!); not sure about Baku but I think it was ~9 hrs from Baku to the border. There is also a ferry from Iran, but I don't have any details on it.