Both.
Let me ask you; would you want to read a book that has an epic idea and a super cool storyline, but looks like it was written by a five year old? The answer to that question was probably no. So I'll ask another one; would you want to read a book with incredible grammar and word play that's extravagant, but the storyline makes absolutely 0 sense and half the time you don't even know what's happening? The answer to that question was also no.
Now obviously I'm exaggerating a little bit, not perfecting grammar doesn't make your writing skills equivalent to a 5 year old, and not having a perfect plot doesn't make your story nonsensical, but the idea is neither one of these things can really and truly exist in a successful way without the other. Both of them are important, and neither one more so than the other. It's as simple as that.
I saw a different answer talk about how you'd have to know your target audience to know how to write the book, but that isn't necessarily true. Even if you are a grammar hungry dinosaur looking for a perfectly written book (grammatically), but even if you are, you're not going to enjoy that book if it quite literally makes no sense. A bunch of perfect grammar with no actual meaning to it is ridiculous. And the same goes the other way around. If you're a plot thirsty dude with a need for good characters and a nice storyline, if you can't even use punctuation correctly half the time, the story, no matter how well planned it is, won't make sense anyways, and their thirst for plot won't be quenched.
So I say the answer is both. One can't live without the other, so don't try to make it that way.