Matsumoto Station on the JR Shinonoi Line is about 20 minutes on foot from the castle. If you'd rather ride, the Town Sneaker loop bus (North Course) leaves from the station's Oshiro exit and reaches the Matsumoto-jō / Shiyakusho-mae stop in about 10 minutes.
From Tokyo, the limited express Azusa runs from Shinjuku along the Chūō and Shinonoi lines and takes about 2 h 30 min. From Nagano, the limited express Shinano takes about 50 minutes. From Nagoya the Shinano takes about 2 h, and from Osaka you take the shinkansen to Nagoya and change to the Shinano, about 3 h 30 min in all.
Driving? Leave the Nagano Expressway at Matsumoto IC, about 3.5 km or 20 minutes from the castle. There's no free parking; the nearest city car parks, Otemon and Matsumoto-jō Kita, are about 8 minutes on foot. Flying in, Shinshu Matsumoto Airport has FDA flights from Kobe, Sapporo and Fukuoka, with a shuttle bus to Matsumoto Station taking about 30 minutes.