I am assuming you have a UK passport. There are several ways but you need a visa to enter Spain and apply for residency when you get here.
Firstly, and most popular, the Non Lucrative Visa. This is primarlly for those wishing to retire to Spain as it doesn't allow you to work. You need to show and annual income of around €35,000 a year for a couple and have private medical insurance if under retirement age. If over retirement age, you can apply for an S1 which transfers your medical cover from UK to Spain.
As you said you wanted to work remotely for a UK company, there is the so-called digital nomad visa. This allows you to work for a non Spanish company and show you would get the regular income plus have private medical insurance to cover you for at least a year. This is for 1 year to start but can be extended up to 5 years in two gos. Each time you reapply you have to show the required income and the medical cover.
There are loads of other visas such as a work visa, student visa etc.
Plenty of information on official sites out there which show the requirements. Whatever visa you get, you would need to apply for residency in the province you are going to be based in within 3 months of arrival.
I would think the digital nomad visa is the one you want and the rules etc are on the official Ministry of the Interior site
Digital Nomad Visa