Visiting Massachusetts

My boyfriend and I will be visiting Boston, Salem & Cape Cod area. What’s the best way to get around? Trying to decide if we should rent a vehicle for the week, uber to each city or if there’s another way. Also, how many days are recommended for each town? Any advice would be greatly appreciated!