Himeji is along the Sanyo shinkansen line from Osaka (30 min) and Kobe (20 min) to Okayama and Hiroshima. A much cheaper option is to take one of the frequent commuter expresses (新快速 shinkaisoku), which charges only the price of a local train and takes 40 minutes from Kobe or one hour from Osaka.
It's easy enough to walk along Otemae-dōri from the station to the castle and back, but buses will also cover the distance in 5 minutes.
Himeji Castle is particularly striking (and crowded) in cherry blossom season in April, when all the trees planted in and around the castle burst burst into white splendor.
Buy, Eat and Drink
All your eating, drinking and souvenir needs will be eagerly met by the gauntlet of vendors that graces the well-trod street between station and castle.
As you only need half a day at most to visit the castle, few visitors stay overnight.