When the Empire was "defeated", all it's resources were split by whomever had the most power to claim them. Military and financial assets. Most of the Imperial fleet scattered into the region of space that Star Killer Base was at, the "Unknown Regions", away from the New Republic. The New Republic didn't wipe out all of the influential political positions throughout the entire galaxy of countless worlds. Not all of those politicians liked the New Republic and they started defecting or channeling resources to the older groups, which the First Order was one of the ones to be born out of that.
As noted in Bloodlines, a canon prequel novel to The Force Awakens (from wikia):
In the years leading up to the destruction of the Hosnian system, the First Order quietly bidded its time preparing for its eventual war with the New Republic. To generate funding to refit and rearm the former Imperial fleet, the First Order used a militia group called the Amaxine warriors as proxies to fund the Nikto crime lord Rinnrivin Di's cartel. Seven years prior to the "Napkin Bombing" at the New Republic senatorial complex on Hosnian Prime, the First Order used the Amaxines to inject billions of Credits as start-up capital into Rinnrivin's cartel, turning the hitherto minor cartel into a major crime syndicate. Establishing a mutual relationship with the Amaxines, Rinnrivin embarked on lucrative smuggling and gambling operations with the proceeds being channeled through shadowy corporations and Centrist sources back to the First Order, which used the money to rebuild its fleet.
In addition, the First Order also recruited several Centrist senators like Lady Carise Sindian as clandestine agents who worked to subvert the New Republic from within. Many Centrists, an informal faction in the New Republic's Galactic Senate who favored a stronger central government and military, admired the Old Empire's leaders and practices. Another proxy of the First Order was Arliz Hadrassian, a former TIE fighter pilot who had become the leader of the Amaxine warriors. While Hadrassian saw the Amaxines as the vanguard of the First Order, Lady Carise regarded her as too volatile to manage. Hadrassian in return was impatient with the Centrists for refusing to secede from the Republic.