Welcome to FlyerTalk hayesdaniel.
One thing I can comment on is the "train" situation. You cannot take a train from Istanbul to Beirut; no rail service in my country unfortunately. You can; however, take a train to Syria and then hop on a bus from there to Beirut.
I really have NO idea how to begin searching for something like that, so you have a bit of research to do.
As for budget airlines, there are a few that fly out of Beirut (via Gulf countries). Just not sure if all have services to Iran. Try flyDubai, Air Arabia and Jazeera.
Have a safe trip. Should you have any specific questions regarding Beirut, please feel free to get in touch.