I wonder if this is even legal?
It's technically legal to produce the basic bricks, since the applicable patents expired in 1989. As for trademarked Lego properties (like the mini-figures, for example) or any which are covered by more recent patents, you can still get away with it as long as you're only producing toys for personal use, and make no attempt to sell them.
But back to the OP's topic: The feasibility of making Lego compatible bricks with cheap 3D printers isn't actually the only question that you're going to have to face; you also need to take into account materials cost. Sure, the "Ultimaker 3D Printer" itself is quite expensive at US $2K -- but even if you gave up on cheaper options and decided to cough up that chunk of change, you also have to keep in mind that the plastic filament to feed the beast also costs money, to the tune of $20 to $80 per spool, depending upon what you're doing. On top of that, not every "printed" component comes out quite right... so you're likely to blow plenty of cash on ultimately wasted filament. Mind you, there are also so many other really cool things you could do with a 3D printer, besides making Lego bricks... but those things will just require that much more filament, and ultimately accomplish the opposite of your stated goal, that of saving money.
So the bottom line is, if you're going to get into 3D printing at all, you really need to do it "for the love of the game" as they say, not to save money. If all you want is cheaper Lego compatible bricks... then you'll probably be better off in the long run just buying generic brand bricks.