There are several types of trains between Salzburg and Werfen. There is what looks like an hourly S-Bahn that makes the trip in 54 minutes and a Regional Express (REX) every two hours that does it in 40 minutes. There is also an occasional EC. All have the same fare, €10,40, one way.
I'm pretty sure when I did it, I was able to get the same fare (at the time) as a walk-up.
I did the trip in 2012. I visited Hohenwerfen Castle, which is the castle on the hill behind Maria when she teaches the children to sing. In addition to the 40 minute train ride, the walk to the castle (there is no public transportation in Werfen that I could find) takes about a half hour, maybe a little less. I don't think the remaining time would be enough to really see the castle.
I know that in addition to the castle, there are ice caves in the area, but I didn't go there so I don't know how long that would take.
If you just want to hike a couple hours from the Bahnhof that should be doable.
For some impossible-to-fathom reason (None Dare Call It [a] Reason), the Einfach-Raus-Ticket is only for 2-5 people. A single person cannot use it!? I was alone, so I couldn't use it. I once blew off a trip where I was going to take an express train from Munich to Vienna, then work my way back slowly, but when I found out I could not use the Einfach Raus Ticket alone, I was so P'd off I will probably never go to Vienna.