The second part of your question is he easy part, if you die whilst still living in and owning the house you need a Will. If these 2 people are the only 2 heirs you need to think about how you want to divide it.
If you want to share it equally, just say you leave x & y 50% each. You can vary the percentages in any way you want. If you want to pay your brother back with a fixed amount, you bequeath him that amount with the residue to the friend.
The first half is not so straightforward. technically if you sell it you may be liable to Capital gains tax on the profit of the share he gifted you, dependent of the the tax threshold and the time lapsed since the gift. Also if at a later date you need to go into a Care Home, they may decide that by giving him the money you have deprived yourself of an asset. (Your age now will play a part in that).
You really need professional advice on this, it is almost as if he has loaned you his share of the house with repayment due at a later date.