You have several realistic options available to you, most of which will occur during your post-JO shore duty.
First, you should understand the mechanics that will lead up to this:
At the end of your first 3 year sea tour, you'll be approaching 5 YCS and you will make a decision to either resign your commission or to 'play the slate' -- put in your preferences for the list of available post-JO shore jobs and serve at least until your shore duty orders are up. You put in a list of 10 preferences and the detailer assigns people according to the "needs of the Navy," your career needs based on performance at sea, and those preferences. Once you commit to a shore duty, you cannot (legally at least) resign until those orders are up, so if you get something that wasn't on your list such as prototype, which happens on occasion, then you have to suck it up and no grad degree for you. The detailer gets more 'points' for 'green' details (top 3) and gets docked for 'red details' (not on your list at all), but he has to fill all the high priority jobs first and foremost.
Having said that, you can REQUEST the following:
1) NROTC instructor. Very difficult to get at reputable schools because there are "non-traditional shore duties" (GSA tours in Afghanistan that are now no longer available, staff on destroyer squadron ASW team that goes underway for a year) that get first priority at the slate. It also allows you to get reduced tuition at most universities because you are considered staff, while incurring no extra commitment, so it's a very popular option thus making it even more competitive. I personally would not hang my hat on getting an NROTC instructor gig.
2) Naval Postgraduate School. This incurs a DH tour commitment, but it is completely free. There are two catches: 1) It's a non-observed tour, which means that you have a period of time as an O-3 where your performance is not evaluated compared to your peers. Can be detrimental to your promotion to screening LCDR and XO at sea if you don't come out of the gate running as a DH at sea. 2) They will generally send you to only study things that are 'useful' to the submarine community (Operations Analysis, Undersea Warfare, a handful of others), so if you're planning on getting an MBA that probably won't happen. NPS's claim to fame is their OA program and cyber-security programs; their other engineering/technical degrees are decent (many of these tie into the USW program) and their MBA program is not very well-regarded.
NPS also has distance learning programs that also incur a time in service commitment.
3) Engineering management masters via CD. This is not a very reputable degree, but it will meet the 'check in the box' for having a Master's in the Navy. The nuke pipeline qualifies you for credits toward this degree.
4) Use the post 9/11 GI bill to go to night school while you are doing a shore duty. This is very doable in MOST shore duty jobs, but be aware if you want to go to graduate school outside of places that have a sub base or Washington DC, then you're going to be SOL. You should also note that very few reputable graduate schools exist around submarine bases, but it also depends on what you want to do. Some slates may also have very few DC jobs and working at the Pentagon is generally longer hours than instructor duty at a sub base.
5) Prototype. You won't be able to go to school while you are a prototype instructor, but one of the options is to either take a 1 year sabbatical to get a master's done with no other military commitments. Another is to go to the Naval War College. Both options incur a DH tour commitment. The NWC is free, but their degrees aren't very reputable outside of the military.
6) PCU -> NWC. After you serve 24 mo on the boat and qualify engineer, you can request to transfer early to a pre-commissioning boat. That will incur another two years to get the boat operational. That eats a year of your shore duty, so you will get sent to NWC to get a master's if you choose to stay in the Navy. If you go to NWC, you incur a DH commitment because it's free to you.
If none of those options are appealing to you, or you just don't want to gamble 2 years of your future on a shore duty lottery, then you will have to resign and use the 9/11 GI bill to attend a university. Your chances of getting a shore duty you want greatly increase if you have a CO who will 'play ball' -- call the detailer and use his senior judgment to put in a word on the best 'fit' for you.